<?php

//2008.7.3 dt
function smarty_function_dateCalender($params, &$smarty)
{
	
	$currentDateToyyyymm = $params["currentDateToyyyymm"];
	$_dayRow = array("",31,28,31,30,31,30,31,31,30,31,30,31);
	$_weekRow = array("jp"=>array("日","月","火","水","木","金","土"),
						     "zh"=>array("日","一","二","三","四","五","六"),
	    				     "en"=>array("SUN","MON","TUE","WEN","SUR","FRI","SAT"));
	$_strYear = "";
	$_strWeek = "";
	$_strDay = "";
	$_language = "jp";
	$_Year;
	$_Month;
	$_Day;
	//$currentDateToyyyymm = '2008-7';
	
	//初始化 begin
	if ($currentDateToyyyymm == "")
	{
		$_Year = date("Y");
		$_Month = date("n");
	}
	else
	{
		$_Year  = date("Y",strtotime($currentDateToyyyymm));
    	$_Month = date("n",strtotime($currentDateToyyyymm));
	}
	
	if ($Day == "") 
	{
		$_Day = date("d");
	}
	else 
	{
		$_Day = $Day;
	}
	
	//初始化 end
	
	//计算闰年的天数
	if ((($_Year%4 == 0) && ($_Year%100!= 0)) || ($_Year%400==0)) $_dayRow[2]= 29;
	
	//显示年份选择 begin
	if($_language == "en")
	{
		$YYYYMM = $_Year."/".$_Month;
	}
	else
	{
		$YYYYMM = $_Year."年".$_Month."月";
	}
	$_strYear .= "<tr>\r\n"; 
    $_strYear .= "<td colspan='7' align='center' bgcolor='#FFFFFF' class='text02'><strong>".$YYYYMM."</strong></td>\r\n";
    $_strYear .= "</tr>\r\n";
    //显示年份选择 end
    
    //显示星期行 begin
    $_strWeek .= "<tr>\r\n";  
	for($i = 0; $i < count($_weekRow[$_language]); $i++) 
	{
		$style = "text02";
		if ($i == 0) $style = "text02 style3";
	    if ($i == count($_weekRow[$_language])- 1) $style = "text02";
		$_strWeek .= "<td width='25' align='center' valign='middle' bgcolor='#FFFFFF' class='".$style."'>".$_weekRow[$_language][$i]."</td>\r\n";   
	}
	$_strWeek .= "</tr>\r\n";
	//显示星期行 end


	//显示日期 begin
	$time = mktime(0,0,0,$_Month,1,$_Year); 
	$firstDay = date("w",$time); //得到当前月的第一天

	$_strDay .= "<tr>\r\n";
	
	for($i = 0; $i < $firstDay; $i++) 
	{
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
	}
	$rownum = 1;
	for($j = 1;$j <= $_dayRow[$_Month]; $j++)
	{
		$date = $_Year."-".$_Month."-".$j;
		//星期天的时候显示星期日的样式
		if ($firstDay == 0) 
			$day = "<span class='style3'>$j</span>";
		//星期6的时候的样式
		else if 
			($firstDay == 6) $day = "<span class='style4'>$j</span>";
		//当天的时候显示红色
		//else if ($_Year.$_Month.$j == date("Ynj")) $day = "<span style='color:red;'>$j</span>";
		//其它情况
		else 
			$day = $j;
		
		$_strDay.="<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>";
		$_strDay.="<a href='#' onclick=\"pageSubmit('".$date."');\">".$day."<br />○</a></td>\r\n";
		//星期6
		if ($firstDay == 6)
		{
			//如果到星期6换行
			if ($j != $_dayRow[$_Month]) 
			{
				$rownum++;
				$_strDay .= "<tr>\r\n";
			}
			$firstDay = -1;
		}
		$firstDay++;
	}
	if ($firstDay != 0)
	{
		for ($i = $firstDay; $i <= 6; $i++)
		{
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			if($i == 6) $_strDay .= "</tr>\r\n";  
		}
	}
	//如果行数小于6，就补一行,如果行数小于5，再补一行
	if ($rownum < 6)
	{
		$_strDay .= "<tr>\r\n";
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
		$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
		$_strDay .= "</tr>\r\n";
		if($rownum < 5)
		{
			$_strDay .= "<tr>\r\n";
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			$_strDay .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>\r\n";
			$_strDay .= "</tr>\r\n";
		}
	}
	////显示日期 end
	
	echo $_strYear.$_strWeek.$_strDay;
}
?>
